
#include "IWindow.h"
#include "member_BProgressBar.h"

using namespace BWE;

member_BProgressBar::member_BProgressBar(BProgressBar* dialog)
{
	boss = dialog;
	align = Align_Center;
	orientation = Orientation_Horizontal;
	value = 0;
	minimum = 0;
	maximum = 100;
}
member_BProgressBar::~member_BProgressBar()
{

}

void member_BProgressBar::freshRects()
{
	BRect crect = boss->clientRect();

	int cx = crect.x();
	int cy = crect.y();
	int cw = crect.width();
	int ch = crect.height();

	float range = maximum - minimum;
	int x, y, w, h;
	if (orientation == Orientation_Vertical)
	{
		x = cx;
		y = cy;
		w = cw;
		h = ch * value / range;
	}
	if (orientation == Orientation_Horizontal)
	{
		x = cx;
		y = cy;
		w = cw * value / range;
		h = ch;
	}
	rect.set(x, y, w, h);

	text = (int)(value / range * 100);
	text << '%';

	const BFont* font = boss->font();
	if (font)
	{
		textSize = font->textSize(text);
		textRect = crect.align(align, textSize);
	}

}
